﻿using System.Globalization;
using System.Windows.Data;
using System.Windows.Media;
using DimensionsHelper.Client.Controls;
using DimensionsHelper.Common.Contracts.Excel;

namespace DimensionsHelper.Client.Converters;

public class BorderStyleToDashArrayConverter : IValueConverter
{
    private static readonly DoubleCollection EmptyDashArray = [];

    public static BorderStyleToDashArrayConverter Instance => new();


    public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
    {
        BorderStyle style = BorderStyle.None;

        if (value is BorderStyle borderStyle)
        {
            style = borderStyle;
        }

        switch (style)
        {
            case BorderStyle.Dotted:
                return BorderGridPens.DotDashArray;

            case BorderStyle.DashDot:
            case BorderStyle.MediumDashDot:
                return BorderGridPens.DashDotDashArray;

            case BorderStyle.DashDotDot:
            case BorderStyle.MediumDashDotDot:
                return BorderGridPens.DashDotDotDashArray;

            case BorderStyle.Dashed:
            case BorderStyle.MediumDashed:
                return BorderGridPens.DashedDashArray;

            case BorderStyle.Thick:
            case BorderStyle.Medium:
            case BorderStyle.Hair:
            case BorderStyle.Double:
            case BorderStyle.Thin:
            case BorderStyle.None:
            default:
                break;
        }

        return EmptyDashArray;
    }

    public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
    {
        return Binding.DoNothing;
    }
}